<?php


namespace App\Http\Controllers\Api;


use App\Http\Controllers\Controller;

use App\library\services\CityService;
use Illuminate\Http\Request;

class CityController extends Controller
{
    /**
     * Author:YangXinPeng
     * 获取省会ID
     * @param Request $request
     * @return mixed
     */
      public function getProvinceId(Request $request)
      {
          $address = $request->get('address');
          if (empty($address)){
              return $this->fail('参数错误');
          }
          $province = substr($address,0,strpos($address,"市"));
          $data = CityService::getProvince($province);
          return $this->success('成功',$data);
      }

    /**
     * Author:YangXinPeng
     * 获取区域
     * @param Request $request
     * @return mixed
     */
      public function getRegions(Request $request)
      {
          $provinceId = $request->get('province');
          if (empty($provinceId)){
              return $this->fail('参数错误');
          }
          $res = CityService::getRgion($provinceId);
          return $this->success('成功',$res);
      }

    /**
     * Author:YangXinPeng
     * 获取所有省会
     * @return array
     */
      public function getProvince()
      {
        $data = CityService::getProvinces();
        return $data;
      }


      public function getDataById(Request $request)
      {
          $id = $request->get('id');
          if (!is_numeric($id)){
              return $this->fail('错误参数');
          }
          $data = CityService::getById($id);
          return  $data;
      }


}
